﻿<%@ WebHandler Language="C#" Class="album" %>

using System;
using System.Web;
using System.Text;
using ExifLibrary;
using System.IO;
using System.Linq;

public class album : IHttpHandler
{

    public void ProcessRequest(HttpContext c)
    {
        c.Response.ContentType = "text/plain";
        try
        {
            StringBuilder s = new StringBuilder();
            s.Append("<ul>");
            string path = c.Server.MapPath("../photo") + "\\" + c.Request["page"] + "\\full";
            
            DirectoryInfo di = new DirectoryInfo(path);
            FileSystemInfo[] files = di.GetFileSystemInfos();
            var orderedFiles = files.OrderBy(f => f.Name);
            foreach (FileSystemInfo filepath in orderedFiles)
            {
                s.Append("<li>");
                try
                {
                    string file = filepath.Name; //.Substring(filepath.LastIndexOf("\\") + 1);
                    s.Append("<img width=\"56\" height=\"56\" src=\"images/dark/imgloader.gif\" rel=\"../photo/" + c.Request["page"] + "/thumbs/" + file + "\"alt=\"thumbnail\" longdesc=\"../photo/" + c.Request["page"] + "/full/" + file + "\"/>");
                  //  s.Append("<div class=\"description\">");
                    //try
                    //{
                    //    ImageFile exif = ImageFile.FromFile(filepath);
                    //    s.Append("<b>Exif Data</b>");
                    //    s.Append("Aperture: " + exif.Properties[ExifTag.ApertureValue] + "<br/>");
                    //    s.Append("Exposure: " + exif.Properties[ExifTag.ExposureTime] + "<br/>");
                    //    s.Append("FocalLength: " + exif.Properties[ExifTag.FocalLength] + "<br/>");
                    //    s.Append("Shutter Speed : " + exif.Properties[ExifTag.ShutterSpeedValue] + "<br/>");
                    //}
                    //catch (Exception)
                    //{
                    //    s.Append("No Exif data Available");
                    //}
                 //   s.Append("</div>");
                }
                catch (Exception ex)
                {
                    c.Response.Write("Error:" + ex.Message);
                }
                s.Append("</li>");
            }
            s.Append("</ul>");
            c.Response.Write(s.ToString());
        }
        catch (Exception ex)
        {
            c.Response.Write("<ul><li>Error:" + ex.Message + "</li></ul>");
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}